﻿using Simple.ISysRepository;
using Simple.Tools;
using SimpleSaas.Common.DataBase;
using SimpleSaas.Entity;
using SimpleSaas.Entity.View;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Simple.SysRepository
/// <summary>
/// 版 本 钢易智企2.0 V 2.0.0 钢易智企2.0
/// Copyright (c) 2023 杭州钢易科技有限公司
/// 创建人：曾东明
/// 日 期：2024
/// 描 述：
/// </summary>
{
	public class SysDatabaseRepository : WholeRepository<SysDatabaseEntity, long>, ISysDatabaseRepository
	{
		public SysDatabaseRepository()
		{

		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="matchCondition"></param>
		/// <returns></returns>
		public ISugarQueryable<SysDatabaseView> Query(Action<ISugarQueryable<SysDatabaseEntity>> matchCondition)
		{
			SimpleCheck.IsNullThrowException(matchCondition);

			var query=dbClient.Queryable<SysDatabaseEntity>();

			matchCondition.Invoke(query);

			return query.Select(dataBase=>new SysDatabaseView()
			{
				Id=dataBase.Id.ToString(),
				DatabaseConnectionStr=dataBase.DatabaseConnectionStr,
				CreationTime=dataBase.CreationTime,
				DisplayName=dataBase.DisplayName,
				MasterFlag=dataBase.MasterFlag,
				Remark=dataBase.Remark,
			});
		}
	}
}
